<?php

// 请求操作界面
use Illuminate\Http\Request;
// 数据库操作
use Illuminate\Support\Facades\DB;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::redirect('/', '/web', 301);

Route::any('api', function () {
    // 尝试查询数据库
    $users = DB::select('select * from user where _id = :id', ['id' => 1]);

    return response()->json([
        'user' => $users,
        'url' => url()->current(),
        'previous' => url()->previous(),
    ]);
});

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});
